package com.itheima.mall.controller;

import com.itheima.mall.dto.OrderDeliveryDto;
import com.itheima.mall.dto.OrderDto;
import com.itheima.mall.dto.OrderMoneyInfo;
import com.itheima.mall.dto.OrderReceiverInfo;
import com.itheima.mall.pojo.Order;
import com.itheima.mall.service.OmsOrderService;
import com.itheima.mall.vo.OrderVo;
import com.itheima.mall.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("order")
public class OmsOrderController {
    @Autowired
    private OmsOrderService omsOrderService;

    /**
     * 批量删除订单
     * @param ids
     * @return
     */
    @PostMapping("delete")
    public ResponseEntity delete(@RequestParam("ids") List<Long> ids) {
        int i = omsOrderService.deleteByIds(ids);
        return ResponseEntity.ok(i);
    }

    /**
     * 查询订单
     * @param orderDto
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("list")
    public ResponseEntity list(OrderDto orderDto,
                  @RequestParam(defaultValue = "1") Integer pageNum,
                  @RequestParam(defaultValue = "5") Integer pageSize
    ) {
        PageResult list = omsOrderService.list(orderDto, pageNum, pageSize);
        return ResponseEntity.ok(list);
    }

    /**
     * 批量关闭订单
     * @param ids
     * @param note
     * @return
     */
    @PostMapping("/update/close")
    public ResponseEntity close(@RequestParam("ids") List<Long> ids, String note) {
        int i = omsOrderService.close(ids, note);
        return ResponseEntity.ok(i);
    }

    /**
     * 批量发货
     * @param deliveryParamList
     * @return
     */
    @PostMapping("update/delivery")
    private ResponseEntity delivery(@RequestBody List<OrderDeliveryDto> deliveryParamList) {
        omsOrderService.delivery(deliveryParamList);
        return ResponseEntity.ok(1);
    }

    /**
     * 修改订单费用信息
     * @param moneyInfoParam
     * @return
     */
    @PostMapping("update/moneyInfo")
    private ResponseEntity moneyInfo(@RequestBody OrderMoneyInfo moneyInfoParam) {
        int i = omsOrderService.moneyInfo(moneyInfoParam);
        return ResponseEntity.ok(i);
    }

    /**
     * 备注订单
     * @param order
     * @return
     */
    @PostMapping("update/note")
    private ResponseEntity note(Order order) {
        int i = omsOrderService.note(order);
        return ResponseEntity.ok(i);
    }

    /**
     * 修改收货人信息
     * @param receiverInfoParam
     * @return
     */
    @PostMapping("update/receiverInfo")
    private ResponseEntity receiverInfo(@RequestBody OrderReceiverInfo receiverInfoParam){
        int i=omsOrderService.receiverInfo(receiverInfoParam);
        return ResponseEntity.ok(i);
    }

    /**
     * 获取订单详情：订单信息、商品信息、操作记录
     * @param id
     * @return
     */
    @GetMapping("{id}")
    private ResponseEntity details(@PathVariable Long id){
    OrderVo vo=omsOrderService.details(id);
    return ResponseEntity.ok(vo);
    }
}
